var app = angular.module("myApp",["globalApp"]);

app.controller("myCtrl",function($scope,$http){
	$scope.reminder = false;
	$scope.close = function(){
		$scope.reminder = false;
	}
	//请求收货人地址
	$http({
        method : "post",
        dataType: "json",
		withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
	        
	    crossDomain: true,
	    contentType: "application/x-www-form-urlencoded",//表单提交
        async:true,
        url : host + "/terminal/shipping/getDefault"
   }).success(function(response){
        if(response.code == 2000){
        	$scope.address = response.data.shipping;
        	$scope.orderCode = window.sessionStorage.orderCode;
        	$scope.totalPrice = window.sessionStorage.totalPrice;
        }else{
        	
        }
    });
    
    //默认选中微信支付
    $scope.ischeckedStyle1 = true; 
    $scope.none1 = false;
    //点击选取支付的方式
    $scope.changeStyle1 = function(){
    	$scope.ischeckedStyle1 = true; 
        $scope.none1 = false;
        $scope.ischeckedStyle2 = false; 
        $scope.none2 = true;
    }
    $scope.changeStyle2 = function(){
    	$scope.ischeckedStyle1 = false; 
        $scope.none1 = true;
    	$scope.ischeckedStyle2 = true; 
        $scope.none2 = false;
    }
    
    //点击立即支付，支付订单
    $scope.toPay = function(){
    	if($scope.ischeckedStyle1 == true){
    		$scope.reminder = true;
    		$scope.message = "暂不支持微信支付"
    	}
    	if($scope.ischeckedStyle2 == true){
    		var params = {
			    orderCode : $scope.orderCode,
			    return_url : url + "paySuccess.html"
			};
			params = $.param(params);
    		$http({
		        method : "post",
		        dataType: "json",
				withCredentials: true,	//跨域名请求。XHR：XMLHttpRequest (XHR) ，基于XML技术的Http请求
			    data : params,
			    crossDomain: true,
			    headers:{'Content-Type': 'application/x-www-form-urlencoded'},
		        async:true,
		        url : host + "/terminal/alipay/mobile"
		   }).success(function(response){
		   	    window.sessionStorage.payHtml = response;
		   	    location.href = "pay.html";
		    });
    	}
    }
})